#include "stdafx.h"
#include "DirectX框架.h"


using namespace std;


#pragma comment(lib, "d3dcompiler.lib")
#pragma comment(lib, "D3D12.lib")
#pragma comment(lib, "dxgi.lib")






static ComPtr<ID3D12RootSignature>		g_RootSignature;
static ComPtr<IDXGIFactory4>			g_mdxgiFactory;

static ComPtr<ID3D12CommandAllocator>		g_DirectCmdListAlloc;
static ComPtr<ID3D12CommandQueue>			g_命令列队;
static ComPtr<ID3D12GraphicsCommandList>	g_命令列表;


//static ComPtr<ID3D12DescriptorHeap>	g_RtvHeap;
static ComPtr<ID3D12DescriptorHeap>	g_DsvHeap;


static DXGI_FORMAT					g_渲染图像格式 = DXGI_FORMAT_R8G8B8A8_UNORM;
static DXGI_FORMAT					g_DepthStencilFormat = DXGI_FORMAT_D24_UNORM_S8_UINT;
static uint8						g_交换链缓存数量 = 2;
static uint8						g_m4xMsaaQuality = 0;

static bool							g_4xMsaaState = false;

//Platform::Exception::CreateException

static S_DX环境						g_DX环境;


void GetHardwareAdapter(IDXGIAdapter1** ppAdapter)
{
	ComPtr<IDXGIAdapter1> adapter;
	*ppAdapter = nullptr;

	for (UINT adapterIndex = 0; DXGI_ERROR_NOT_FOUND != g_mdxgiFactory->EnumAdapters1(adapterIndex, &adapter); adapterIndex++)
	{
		DXGI_ADAPTER_DESC1 desc;
		adapter->GetDesc1(&desc);

		if (desc.Flags & DXGI_ADAPTER_FLAG_SOFTWARE)
		{
			// 不要选择基本呈现驱动程序适配器。
			continue;
		}

		// 检查适配器是否支持 Direct3D 12，但不要创建
		// 仍为实际设备。
		if (SUCCEEDED(D3D12CreateDevice(adapter.Get(), D3D_FEATURE_LEVEL_12_0, _uuidof(ID3D12Device), nullptr)))
		{
			break;
		}
	}

	*ppAdapter = adapter.Detach();
}

#ifndef ReleaseCom
#define ReleaseCom(x) { if(x){ x->Release(); x = 0; } }
#endif

void f_LogOutputDisplayModes(IDXGIOutput* output, DXGI_FORMAT format)
{
	UINT count = 0;
	UINT flags = 0;

	// Call with nullptr to get list count.
	output->GetDisplayModeList(format, flags, &count, nullptr);

	std::vector<DXGI_MODE_DESC> modeList(count);
	output->GetDisplayModeList(format, flags, &count, &modeList[0]);

	for (auto& x : modeList)
	{
		UINT n = x.RefreshRate.Numerator;
		UINT d = x.RefreshRate.Denominator;
		std::wstring text =
			L"Width = " + std::to_wstring(x.Width) + L" " +
			L"Height = " + std::to_wstring(x.Height) + L" " +
			L"Refresh = " + std::to_wstring(n) + L"/" + std::to_wstring(d) +
			L"\n";

		//::OutputDebugString(text.c_str());
	}
}

void f_LogAdapterOutputs(IDXGIAdapter* adapter)
{
	UINT i = 0;
	IDXGIOutput* output = nullptr;
	while (adapter->EnumOutputs(i, &output) != DXGI_ERROR_NOT_FOUND)
	{
		DXGI_OUTPUT_DESC desc;
		output->GetDesc(&desc);

		std::wstring text = L"***Output: ";
		text += desc.DeviceName;
		text += L"\n";
		//OutputDebugString(text.c_str());

		f_LogOutputDisplayModes(output, g_渲染图像格式);

		ReleaseCom(output);

		++i;
	}
}

void f_LogAdapters(IDXGIFactory4* mdxgiFactory)
{
	UINT i = 0;
	IDXGIAdapter* adapter = nullptr;
	std::vector<IDXGIAdapter*> adapterList;
	while (mdxgiFactory->EnumAdapters(i, &adapter) != DXGI_ERROR_NOT_FOUND)
	{
		DXGI_ADAPTER_DESC desc;
		adapter->GetDesc(&desc);

		std::wstring text = L"***Adapter: ";
		text += desc.Description;
		text += L"\n";

		OutputDebugString(text.c_str());

		adapterList.push_back(adapter);

		++i;
	}

	for (size_t i = 0; i < adapterList.size(); ++i) {
		f_LogAdapterOutputs(adapterList[i]);
		ReleaseCom(adapterList[i]);
	}
}








S_DirectX3D绘图框架::S_DirectX3D绘图框架()
{
	m_CurrBackBuffer = 0;
	m_CurrentFence = 0;


#ifdef _DEBUG 
	{
		ComPtr<ID3D12Debug> debug控制;
		auto err = D3D12GetDebugInterface(IID_PPV_ARGS(&debug控制));
		//ThrowIfFailed()
		debug控制->EnableDebugLayer();

	}
#endif

	HRESULT hardware = CreateDXGIFactory1(IID_PPV_ARGS(&g_mdxgiFactory));
	//g_mdxgiFactory->EnumWarpAdapter(IID_PPV_ARGS(&m_pWarpAdapter));

	hardware = D3D12CreateDevice(0, D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&m_设备));
	if (FAILED(hardware)) {
		std::cout << "创建DX设备失败" << std::endl;
	}

	// Fallback to WARP device.
	if (FAILED(hardware)) {
		ComPtr<IDXGIAdapter> pWarpAdapter;
		hardware = g_mdxgiFactory->EnumWarpAdapter(IID_PPV_ARGS(&pWarpAdapter));
		hardware = D3D12CreateDevice(pWarpAdapter.Get(), D3D_FEATURE_LEVEL_11_0, IID_PPV_ARGS(&m_设备));
	}


	//ID3D12RootSignature* 命令列表 = gRootSignature.Get();
	//ID3D12CommandAllocator** a = gDirectCmdListAlloc.GetAddressOf();
	//ComPtr<IDXGIAdapter1> adapter;
	//GetHardwareAdapter(&adapter);

	
	m_设备->CreateFence(0, D3D12_FENCE_FLAG_NONE, IID_PPV_ARGS(&m_Fence));
	//gDirectCmdListAlloc
	m_RTV_size = m_设备->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
	m_DSV_size = m_设备->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_DSV);
	m_CbvUav_size = m_设备->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_CBV_SRV_UAV);




	D3D12_FEATURE_DATA_MULTISAMPLE_QUALITY_LEVELS ms质量等级;
	ms质量等级.Format = g_渲染图像格式;
	ms质量等级.SampleCount = 4;
	ms质量等级.Flags = D3D12_MULTISAMPLE_QUALITY_LEVELS_FLAG_NONE;
	ms质量等级.NumQualityLevels = 0;

	m_设备->CheckFeatureSupport(D3D12_FEATURE_MULTISAMPLE_QUALITY_LEVELS, &ms质量等级, sizeof(ms质量等级));

	g_m4xMsaaQuality = ms质量等级.NumQualityLevels;
	assert(g_m4xMsaaQuality > 0 && "Unexpected MSAA quality level.");



#ifdef _DEBUG
	f_LogAdapters(g_mdxgiFactory.Get());
#endif



	f_创建命令列队();




	g_DX环境.设备 = m_设备;
	g_DX环境.命令列队 = g_命令列队.Get();
	g_DX环境.命令列表 = g_命令列表.Get();


}

bool S_DirectX3D绘图框架::f_创建命令列队()
{
	D3D12_COMMAND_QUEUE_DESC queuedesc = {};
	queuedesc.Type = D3D12_COMMAND_LIST_TYPE_DIRECT;
	queuedesc.Priority = 0;
	queuedesc.Flags = D3D12_COMMAND_QUEUE_FLAG_NONE;
	queuedesc.NodeMask = 0;

	HRESULT hr = m_设备->CreateCommandQueue(&queuedesc, IID_PPV_ARGS(&g_命令列队));
	if (FAILED(hr)) {
		std::cout << "命令列表创建失败" << std::endl;
		return false;
	}

	hr = m_设备->CreateCommandAllocator(D3D12_COMMAND_LIST_TYPE_DIRECT, IID_PPV_ARGS(g_DirectCmdListAlloc.GetAddressOf()));
	if (FAILED(hr)) {
		std::cout << "命令列表创建失败" << std::endl;
		return false;
	}


	hr = m_设备->CreateCommandList(
		0,
		D3D12_COMMAND_LIST_TYPE_DIRECT,
		g_DirectCmdListAlloc.Get(),
		0,
		IID_PPV_ARGS(g_命令列表.GetAddressOf())
	);

	
	//g_命令列表->Close();

	return true;
}

bool S_DirectX3D绘图框架::f_创建WIN交换链(HINSTANCE& hInstance, HWND& hWnd, ivec2 size) {
	
	/*DXGI_SWAP_CHAIN_DESC sd = {};
	sd.BufferDesc.Width = size.x;
	sd.BufferDesc.Height = size.y;
	sd.BufferDesc.RefreshRate.Numerator = 60;
	sd.BufferDesc.RefreshRate.Denominator = 1;
	sd.BufferDesc.Format = g_渲染图像格式;
	sd.BufferDesc.ScanlineOrdering = DXGI_MODE_SCANLINE_ORDER_UNSPECIFIED;
	sd.BufferDesc.Scaling = DXGI_MODE_SCALING_UNSPECIFIED;
	sd.SampleDesc.Count = g_4xMsaaState ? 4 : 1;
	sd.SampleDesc.Quality = g_4xMsaaState ? (g_m4xMsaaQuality - 1) : 0;
	sd.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT;
	sd.BufferCount = g_交换链缓存数量;
	sd.OutputWindow = hWnd;
	sd.Windowed = true;
	sd.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
	sd.Flags = DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH;

	ComPtr<IDXGISwapChain> m_交换链A;
	m_交换链A.Reset();
	HRESULT hr = g_mdxgiFactory->CreateSwapChain(g_命令列队.Get(), &sd, m_交换链A.GetAddressOf());
	if (FAILED(hr)) {
		cout << "交换链创建失败" << endl;
		return false;
	}*/

	//DXGI_ALPHA_MODE_UNSPECIFIED
	if (1) {
		m_交换链1.Reset();

		DXGI_SWAP_CHAIN_DESC1 sd1 = {};
		SecureZeroMemory(&sd1, sizeof(sd1));

		sd1.Width = size.x;
		sd1.Height = size.y;

		sd1.Format = g_渲染图像格式;
		sd1.Scaling = DXGI_SCALING_STRETCH;
		sd1.BufferUsage = DXGI_USAGE_RENDER_TARGET_OUTPUT | DXGI_USAGE_SHADER_INPUT;
		sd1.SwapEffect = DXGI_SWAP_EFFECT_FLIP_DISCARD;
		sd1.AlphaMode = DXGI_ALPHA_MODE_UNSPECIFIED;
		sd1.SampleDesc.Count = g_4xMsaaState ? 4 : 1;
		sd1.SampleDesc.Quality = g_4xMsaaState ? (g_m4xMsaaQuality - 1) : 0;
		sd1.Flags = 0;

		sd1.BufferCount = g_交换链缓存数量;



		HRESULT hr = g_mdxgiFactory->CreateSwapChainForHwnd(g_命令列队.Get(), hWnd, &sd1, 0, 0, m_交换链1.GetAddressOf());
		if (FAILED(hr)) {
			cout << "交换链创建失败" << endl;
			return false;
		}

		
		hr = m_交换链1->QueryInterface(IID_PPV_ARGS(m_交换链3.GetAddressOf()));
		if (FAILED(hr)) {
			cout << "交换链接口查询失败" << endl;
			return false;
		}
	}

	



	m_视口.TopLeftX = 0.0f;
	m_视口.TopLeftY = 0.0f;
	m_视口.Width = size.x;
	m_视口.Height = size.y;
	m_视口.MinDepth = 0.0;
	m_视口.MaxDepth = 1.0;
	g_命令列表->RSSetViewports(1, &m_视口);

	m_裁剪 = { 0,0, size.x/2, size.y/2 };
	g_命令列表->RSSetScissorRects(1, &m_裁剪);


	

	m_CurrBackBuffer = m_交换链3->GetCurrentBackBufferIndex();

	f_创建渲染目标视图();


	return true;
}


bool S_DirectX3D绘图框架::f_创建描述符()
{
	D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc;
	rtvHeapDesc.NumDescriptors = g_交换链缓存数量;
	rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
	rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
	rtvHeapDesc.NodeMask = 0;

	HRESULT hr = m_设备->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(m_渲染目标视图堆.pHeap.GetAddressOf()));
	if (FAILED(hr)) {
		MessageBox(0, L"创建 Rtv 描述符失败", 0, 0);
		return false;
	}


	D3D12_DESCRIPTOR_HEAP_DESC dsvHeapDesc;
	dsvHeapDesc.NumDescriptors = 1;
	dsvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_DSV;
	dsvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
	dsvHeapDesc.NodeMask = 0;

	hr = m_设备->CreateDescriptorHeap(&dsvHeapDesc, IID_PPV_ARGS(g_DsvHeap.GetAddressOf()));
	if (FAILED(hr)) {
		MessageBox(0, L"创建 Dsv 描述符失败", 0, 0);
		return false;
	}





	return true;
}

bool S_DirectX3D绘图框架::f_创建渲染目标视图()
{
	m_交换链缓存.resize(g_交换链缓存数量);


	D3D12_DESCRIPTOR_HEAP_DESC rtvHeapDesc;
	ZeroMemory(&rtvHeapDesc, sizeof(rtvHeapDesc));
	rtvHeapDesc.NumDescriptors = g_交换链缓存数量;
	rtvHeapDesc.Type = D3D12_DESCRIPTOR_HEAP_TYPE_RTV;
	rtvHeapDesc.Flags = D3D12_DESCRIPTOR_HEAP_FLAG_NONE;
	rtvHeapDesc.NodeMask = 0;
	HRESULT hr = m_设备->CreateDescriptorHeap(&rtvHeapDesc, IID_PPV_ARGS(m_渲染目标视图堆.pHeap.GetAddressOf()));
	m_渲染目标视图堆.usedEntries = 1;

	

	D3D12_RENDER_TARGET_VIEW_DESC desc = []() {
		D3D12_RENDER_TARGET_VIEW_DESC desc;
		desc.ViewDimension = D3D12_RTV_DIMENSION_TEXTURE2D;
		desc.Format = g_渲染图像格式;
		desc.Texture2D.MipSlice = 0;
		desc.Texture2D.PlaneSlice = 0;
		return desc;
	}();
	


	D3D12_CPU_DESCRIPTOR_HANDLE 渲染目标视图堆(m_渲染目标视图堆.pHeap->GetCPUDescriptorHandleForHeapStart());
	for (uint8 i = 0; i < g_交换链缓存数量; ++i) {
		m_交换链3->GetBuffer(i, IID_PPV_ARGS(&m_交换链缓存[i]));

		m_设备->CreateRenderTargetView(m_交换链缓存[i].Get(), &desc, 渲染目标视图堆);
		渲染目标视图堆.ptr += m_渲染目标视图堆.usedEntries * m_设备->GetDescriptorHandleIncrementSize(D3D12_DESCRIPTOR_HEAP_TYPE_RTV);
	}

	return true;
}



bool S_DirectX3D绘图框架::f_创建深度模板视图(ivec2 size) {
	S_纹理创建参数 深度模板创建参数 = {0};

	深度模板创建参数.size.x = size.x;
	深度模板创建参数.size.y = size.y;
	深度模板创建参数.size.z = 1;

	深度模板创建参数.format = DXGI_FORMAT::DXGI_FORMAT_R32_FLOAT;
	深度模板创建参数.type = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;
	深度模板创建参数.mip = 1;
	深度模板创建参数.sample = g_交换链缓存数量;
	f_取纹理采样级别(dynamic_cast<ID3D12Device*>(m_设备), 深度模板创建参数);
	深度模板创建参数.dim;


	S_DX纹理缓存* 深度模板 = new S_DX纹理缓存();

	深度模板->f_创建内存对象(&深度模板创建参数, m_设备);

	//ComPtr<ID3D12DepthStencilView> a; dsvHeapDesc
	m_设备->CreateDepthStencilView(m_DepthStencilBuffer.Get(), 0, g_DsvHeap->GetCPUDescriptorHandleForHeapStart());
	
	//从资源状态转换为资源缓存区
	/*g_命令列表->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(
		m_DepthStencilBuffer.Get(),
		D3D12_RESOURCE_STATE_COMMON, 
		D3D12_RESOURCE_STATE_DEPTH_WRITE)
	);*/


	return false;
}








void S_DirectX3D绘图框架::f_重置视口(ivec2 size)
{
	HRESULT err = 0;

	f_刷新命令列表();

	g_命令列表->Reset(g_DirectCmdListAlloc.Get(), NULL);

	

	for (int i = 0; i < g_交换链缓存数量; ++i)
		m_交换链缓存[i].Reset();
	m_DepthStencilBuffer.Reset();


	err = m_设备->GetDeviceRemovedReason();
	err = m_交换链3->ResizeBuffers(g_交换链缓存数量, size.x, size.y, g_渲染图像格式, DXGI_SWAP_CHAIN_FLAG_ALLOW_MODE_SWITCH);
	m_CurrBackBuffer = 0;






	//GetDeviceRemovedReason()
	CD3DX12_CPU_DESCRIPTOR_HANDLE rtvHeapHandle(m_渲染目标视图堆.pHeap->GetCPUDescriptorHandleForHeapStart());
	for (UINT i = 0; i < g_交换链缓存数量; i++) {
		err = m_交换链3->GetBuffer(i, IID_PPV_ARGS(m_交换链缓存[i].GetAddressOf()));
		m_设备->CreateRenderTargetView(m_交换链缓存[i].Get(), nullptr, rtvHeapHandle);
		rtvHeapHandle.Offset(1, m_RTV_size);
	}


	// Create the depth/stencil buffer and view.
	D3D12_RESOURCE_DESC depthStencilDesc;
	depthStencilDesc.Dimension = D3D12_RESOURCE_DIMENSION_TEXTURE2D;
	depthStencilDesc.Alignment = 0;
	depthStencilDesc.Width = size.x;
	depthStencilDesc.Height = size.y;
	depthStencilDesc.DepthOrArraySize = 1;
	depthStencilDesc.MipLevels = 1;

	depthStencilDesc.Format = DXGI_FORMAT_R24G8_TYPELESS;

	depthStencilDesc.SampleDesc.Count = g_4xMsaaState ? 4 : 1;
	depthStencilDesc.SampleDesc.Quality = g_4xMsaaState ? (g_m4xMsaaQuality - 1) : 0;
	depthStencilDesc.Layout = D3D12_TEXTURE_LAYOUT_UNKNOWN;
	depthStencilDesc.Flags = D3D12_RESOURCE_FLAG_ALLOW_DEPTH_STENCIL;




	D3D12_CLEAR_VALUE optClear;
	optClear.Format = g_DepthStencilFormat;
	optClear.DepthStencil.Depth = 1.0f;
	optClear.DepthStencil.Stencil = 0;
	/*m_设备->CreateCommittedResource(
		&CD3DX12_HEAP_PROPERTIES(D3D12_HEAP_TYPE_DEFAULT),
		D3D12_HEAP_FLAG_NONE,
		&depthStencilDesc,
		D3D12_RESOURCE_STATE_COMMON,
		&optClear,
		IID_PPV_ARGS(m_DepthStencilBuffer.GetAddressOf()));*/



	// Create descriptor to mip level 0 of entire resource using the format of the resource.
	D3D12_DEPTH_STENCIL_VIEW_DESC dsvDesc;
	dsvDesc.Flags = D3D12_DSV_FLAG_NONE;
	dsvDesc.ViewDimension = D3D12_DSV_DIMENSION_TEXTURE2D;
	dsvDesc.Format = g_DepthStencilFormat;
	dsvDesc.Texture2D.MipSlice = 0;
	m_设备->CreateDepthStencilView(m_DepthStencilBuffer.Get(), &dsvDesc, g_DsvHeap->GetCPUDescriptorHandleForHeapStart());




	/*g_命令列表->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(m_DepthStencilBuffer.Get(),
		D3D12_RESOURCE_STATE_COMMON, D3D12_RESOURCE_STATE_DEPTH_WRITE));*/



	// Execute the resize commands.
	g_命令列表->Close();
	ID3D12CommandList* cmdsLists[] = { g_命令列表.Get() };
	g_命令列队->ExecuteCommandLists(_countof(cmdsLists), cmdsLists);

	f_刷新命令列表();






	// Update the viewport transform to cover the client area.
	m_视口.TopLeftX = 0;
	m_视口.TopLeftY = 0;
	m_视口.Width = static_cast<float>(size.x);
	m_视口.Height = static_cast<float>(size.y);
	m_视口.MinDepth = 0.0f;
	m_视口.MaxDepth = 1.0f;

	m_裁剪 = { 0, 0, size.x, size.y };




}

ID3D12Resource* S_DirectX3D绘图框架::f_CurrentBackBuffer() const
{
	return m_交换链缓存[m_CurrBackBuffer].Get();
}

D3D12_CPU_DESCRIPTOR_HANDLE S_DirectX3D绘图框架::f_CurrentBackBufferView() const {
	return CD3DX12_CPU_DESCRIPTOR_HANDLE(
		m_渲染目标视图堆.pHeap->GetCPUDescriptorHandleForHeapStart(),
		m_CurrBackBuffer,
		m_RTV_size
	);
}

void S_DirectX3D绘图框架::f_刷新命令列表()
{
	++m_CurrentFence;
	g_命令列队->Signal(m_Fence.Get(), m_CurrentFence);

	if (m_Fence->GetCompletedValue() < m_CurrentFence) {
		//HANDLE eventHandle = CreateEventEx(nullptr, false, false, EVENT_ALL_ACCESS);
		//m_Fence->SetEventOnCompletion(m_CurrentFence, eventHandle);

		//WaitForSingleObject(eventHandle, INFINITE);
		//CloseHandle(eventHandle);

	}
}





void* S_DirectX3D绘图框架::f_get命令列表()
{
	return g_命令列表.Get();
}

void * S_DirectX3D绘图框架::f_get环境()
{
	return &g_DX环境;
}

S_帧缓存 * S_DirectX3D绘图框架::f_创建帧缓存()
{
	return nullptr;
}


bool S_DirectX3D绘图框架::f_绘制(S_协处理设备& dev) {
	//return false;

	g_DirectCmdListAlloc->Reset();
	g_命令列表->Reset(g_DirectCmdListAlloc.Get(), 0);



	//auto* CurrentBackBuffe = f_CurrentBackBuffer();
	//g_命令列表->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(f_CurrentBackBuffer(), D3D12_RESOURCE_STATE_PRESENT, D3D12_RESOURCE_STATE_RENDER_TARGET));
	
	g_命令列表->RSSetViewports(1, &m_视口);
	g_命令列表->RSSetScissorRects(1, &m_裁剪);

	//g_命令列表->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(CurrentBackBuffe, D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));

	auto CurrentBackBufferView = f_CurrentBackBufferView();

	
	float32 color[4] = { 0,0,0,1 };
	g_命令列表->ClearRenderTargetView(f_CurrentBackBufferView(), color, 0,0);
	uint32 b = 0;
	//g_命令列表->ResourceBarrier(1, &CD3DX12_RESOURCE_BARRIER::Transition(f_CurrentBackBuffer(), D3D12_RESOURCE_STATE_RENDER_TARGET, D3D12_RESOURCE_STATE_PRESENT));
	//auto& a = g_DsvHeap->GetCPUDescriptorHandleForHeapStart();
	//g_命令列表->ClearDepthStencilView(a, D3D12_CLEAR_FLAG_DEPTH | D3D12_CLEAR_FLAG_STENCIL, 1.0f, 0, 0, 0);


	//g_命令列表->OMSetRenderTargets(1, &CurrentBackBufferView, false, &g_DsvHeap->GetCPUDescriptorHandleForHeapStart());


	g_命令列表->Close();

	ID3D12CommandList* cmdsList[] = { g_命令列表.Get() };
	g_命令列队->ExecuteCommandLists(_countof(cmdsList), cmdsList);

	m_交换链1->Present(0, 0);
	m_CurrBackBuffer = (m_CurrBackBuffer + 1) % g_交换链缓存数量;


	f_刷新命令列表();

	return false;
}

void S_DirectX3D绘图框架::f_alloc(S_协处理设备& dev)
{
}

void S_DirectX3D绘图框架::f_End(S_协处理设备& dev)
{
}








